package com.xposed.xinhao;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.xposed.xinhao.utils.LogUtils;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

public class JDWEBActivity extends AppCompatActivity {

    private final static String COOKIE = "shshshfpa=ed9c7059-4183-5c7c-5b4a-ab5ebb3c7a1a-1559123486; shshshfpb=tCTVAHtVu3wmEJ8hxUojZnA%3D%3D; areaId=16; pin=jd_71f71990dbe62; user-key=1b008d05-794a-4e1b-ba98-d76b7831def6; _pst=jd_71f71990dbe62; unick=jd_71f71990dbe62; _tp=%2FhAJgbMTLzaQAmE3ChgE8B5zoATzGwVJx9vyo7R56UE%3D; pinId=8uLkrrRYu9wNImJMjr8oH7V9-x-f3wj7; ipLoc-djd=16-1303-48713-48746.586846473; ipLocation=%u798f%u5efa; answer-code=\"\"; __jdu=1559123487448515758244; mba_muid=1559123487448515758244; __tak=4c5906d7e4587de0bcc4e6f0e766bca1f35d393d07a8210d3a5216e64b392c2e0a328a1201e74f2bb8dd55c8ed349c4bec9e41f155aff9bb2ec6ead4508df405970043543b74c2ae0e81aa3463d61ffb; qd_uid=K2K8ATG7-1B3ADB0NFZRMZZDWUCHO; qd_fs=1572860111765; logintype=wx; npin=jd_71f71990dbe62; wxa_level=1; retina=0; webp=1; sc_width=400; block_call_jdapp=11; wq_area=16_1303_3483_0; wq_uits=%7Cal%2C2%7Ccid%2C1303%7Cug%2C1; wq_prior=2; rurl=https%3A%2F%2Fwqs.jd.com%2Fmy%2Findexv2.shtml%3Fptag%3D138631.36.4; visitkey=37646551758644072; mt_xid=V2_52007VwMWVlVYUVgaQB9ZAG4HElZbXFtZGkwpWwM0VhcFD1xOXhpPHEAAZ1cQTg1QB1kDShwMUDBRFFReWlNfL0oYXA17AxJOXFxDWhhCGVkOZQoiUG1YYlMXSBxYDGACG2JdXVRd; wlfstk_smdl=yil29zblu2wa9outiixqm5o3n5t3hezf; qd_ls=1573010043607; qd_ts=1573021193183; qd_sq=5; _modc=098f6bcd4621d373cade4e832627b4f6; string123=98B3E3E36011A21FB94D0D6759F665E5112; wqmnx=1bcd1c43jdm356a3e3a6hpea2b4e4130; wq_logid=1573021292.997237378; cid=9; __wga=1573021291898.1573021291898.1572941615312.1572941615312.1.2; PPRD_P=UUID.1559123487448515758244-CT.138631.36.4-LOGID.1573021291915.1987381581; sk_history=15936338139%2C; qd_ad=-%7C-%7C-%7C-%7C0; unpl=V2_ZzNsbRBeF0dxCxUGZx0MDGAfFwpGAl9FIg5DSHpMXQ1iBEFeR1YUQGlJKFRzEVQZJkB8XUpWSgklTShUehhaAWAzEVxCX18VdRRHU2oZWQ5lChleRmdDJXUJR1V6GloGYQsibXJXQSV0OEZQfxFcBmUGG1tHUkoRdQxAUHIaWQBXCxQNEFQWFHUURQR7HUAAZVcVQUsEShxpWxZWfBwPAGIAGg8RZ0UT; __jdv=122270672|kong|t_1000027279_100756|zssc|c8ec52bc-5a86-4f5d-af74-0d0946b240fd-p_1999-pr_1908-at_100756|1573022304214; 3AB9D23F7A4B3C9B=OQX7W5PVNUJARG2WLWGFXAY3USULSINXLW4FEMEWYNMY6LV4MHIJSQU4GV2JHNFQCYSDZLAQJZEFA3IIVGH4ZLTQDQ; shshshfp=7cd3d296ea3167ccf4bbc726eaec336d; _distM=105854669226; __jda=122270672.1559123487448515758244.1559123487.1573020883.1573022304.17; __jdc=122270672; thor=C9F7B1023BA5EC62B3FD9BBE3681AA34ED3AAECFFA478222BC695AE55490EDF09DB8FD09C215F3DDACF711C0C1F5E194D38B46587E3E1254CE7C1976EC1F91C4BB5AEF3C4104DBECA6528F229FA9CFE332ADC2A5133B992E905ED763457FC3DF65CCCB8C4F51701D39F2DBB8AECA7CB1F1138504D2EE47A377790A5E97C5A25ACAF60C78996D8023589E44ABE476C4F5412C13F8F7807FCAA32778F4F63F11E4; cn=1; __jdb=122270672.65.1559123487448515758244|17.1573022304; shshshsID=143fc3f9f43eacf2324313ca7f0b6164_40_1573025122865; JSESSIONID=4FC28A6D84B132389E45C7481B66BA0E.s1";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jd_web);

//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                requestAddCart();
//            }
//        }).start();

        String s = "{&quot;total_amount&quot;:&quot;9.90&quot;,&quot;body&quot;:&quot;订单号Y1191112270579412405&quot;,&quot;timeout_express&quot;:&quot;12h&quot;,&quot;subject&quot;:&quot;订单付款&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;,&quot;passback_params&quot;:&quot;yiwugou_3630665,9.90&quot;,&quot;out_trade_no&quot;:&quot;Y1191112270579412405&quot;}";
        LogUtils.e(s.replace("&quot;","\""));


    }

    /**
     * 加入购物车
     */
    private void requestAddCart() {
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("https://cart.jd.com/gate.action?pid=59411051021&pcount=1&ptype=1")
                .get()
                .addHeader("Cookie", COOKIE)
                .build();
        try {
            Response response = client.newCall(request).execute();
            if (response.code() != 200)
                return;
            ResponseBody body = response.body();
            if (body == null)
                return;
            LogUtils.e("加入购物车：" + body.string());
            requestGetOrderInfo();
        } catch (IOException e) {
            e.printStackTrace();
            LogUtils.e("加入购物车：" + e.getMessage());
        }
    }

    /**
     * 进入结算页面
     * */
    private void requestGetOrderInfo(){

        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("https://trade.jd.com/shopping/order/getOrderInfo.action")
                .get()
                .addHeader("Cookie", COOKIE)
                .build();
        try {
            Response response = client.newCall(request).execute();
            if (response.code() != 200)
                return;
            ResponseBody body = response.body();
            if (body == null)
                return;
            LogUtils.e("进入结算页面：" + body.string());
        } catch (IOException e) {
            e.printStackTrace();
            LogUtils.e("进入结算页面：" + e.getMessage());
        }
    }

}
